package cn.edu.stu.syllabus.widgets;

import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import butterknife.BindView;
import butterknife.ButterKnife;
import cn.edu.stu.syllabus.R;
import cn.edu.stu.syllabus.repository.takeout.local.TakeOutInfoEntry;
import cn.edu.stu.syllabus.datas.MenuCounterHolder;

/**
 * Created by daidaijie on 2017/4/15.
 */

public class BottomDishesMenuViewHolder implements View.OnClickListener {

    @BindView(R.id.sumPriceTextView)
    public TextView mSumPriceTextView;
    @BindView(R.id.unCalcNumTextView)
    public TextView mUnCalcNumTextView;
    @BindView(R.id.submitButton)
    public Button mSubmitButton;
    @BindView(R.id.div_line)
    public View mDivLine;
    @BindView(R.id.shoppingImageView)
    public ImageView mShoppingImageView;
    @BindView(R.id.bottomView)
    public View mBottomView;

    OnBottomClickListener mOnBottomClickListener;

    boolean isCallBottom;

    public BottomDishesMenuViewHolder(final View view, final TakeOutInfoEntry takeOutInfoEntry) {
        ButterKnife.bind(this, view);

        isCallBottom = false;
        mBottomView.setOnClickListener(this);
        mShoppingImageView.setOnClickListener(this);
        mSubmitButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                PhoneDialog.createCallPhoneDialog(
                        view.getContext(), takeOutInfoEntry.getPhoneList()
                ).show();
            }
        });
        mSubmitButton.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                PhoneDialog.createCopyPhoneNumberDialog(
                        view.getContext(), takeOutInfoEntry.getPhoneList()
                ).show();
                return true;
            }
        });
    }

    public void setMenuCounter(MenuCounterHolder holder) {
        mSumPriceTextView.setText("¥" + String.format("%.2f", holder.sumPrice));
        mUnCalcNumTextView.setText("不可计价: " + holder.uncalcableNum + "份");
        if (holder.uncalcableNum == 0) {
            mUnCalcNumTextView.setVisibility(View.GONE);
            mDivLine.setVisibility(View.GONE);
        } else {
            mUnCalcNumTextView.setVisibility(View.VISIBLE);
            mDivLine.setVisibility(View.VISIBLE);
        }
        if (holder.sumNum == 0) {
            isCallBottom = false;
        } else {
            isCallBottom = true;
        }
    }

    @Override
    public void onClick(View v) {
        if (isCallBottom && mOnBottomClickListener != null) {
            mOnBottomClickListener.onBottomClick();
        }
    }

    public OnBottomClickListener getOnBottomClickListener() {
        return mOnBottomClickListener;
    }

    public void setOnBottomClickListener(OnBottomClickListener onBottomClickListener) {
        mOnBottomClickListener = onBottomClickListener;
    }

    public interface OnBottomClickListener {
        void onBottomClick();
    }


}
